﻿using CCWin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebSocketChat.Client
{
    public partial class HeadImageForm : CCSkinMain
    {
        Action<string> ChangeHeadImage;
        public HeadImageForm(Action<string> ChangeHeadImage)
        {
            InitializeComponent();
            this.ChangeHeadImage = ChangeHeadImage;
        }

        private void HeadImageForm_Load(object sender, EventArgs e)
        {
            int x = 36;
            int y = 31;
            for (int i = 1; i < 31; i++)
            {

                PictureBox pb = new PictureBox();
                pb.Image = Properties.Resources.ResourceManager.GetObject("head" + i) as Bitmap;
                pb.Name = "head" + i;
                pb.Cursor = Cursors.Hand;
                pb.SizeMode = PictureBoxSizeMode.StretchImage;
                pb.Width = 70;
                pb.Height = 70;
                pb.Location = new Point(x, y);
                pb.Click += Pb_Click;
                this.Controls.Add(pb);

                if (i % 7 == 0)
                {
                    y += 72;
                    x = 36;
                }
                else
                    x += 72;
            }
        }

        private void Pb_Click(object sender, EventArgs e)
        {
            foreach (var item in this.Controls)
            {
                PictureBox pic = item as PictureBox;
                if (pic != null)
                    pic.BorderStyle = BorderStyle.None;
            }
            PictureBox pb = sender as PictureBox;
            if (pb != null)
            {
                pb.BorderStyle = BorderStyle.Fixed3D;
                sttPicture.SetToolTip(pb, "已设为当前头像");
                ChangeHeadImage(pb.Name);
            }
        }
    }
}
